<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="Generator" content="xnr®">
    <meta name="Author" content="小男人-923227829@qq.com">
    <meta name="sysKeyworremark" content="">
    <meta name="Description" content="">
    <title>系统配置</title>
    <link rel="stylesheet" href="../inc/layui/css/layui.css">
    <link rel="stylesheet" href="../css/comm.css">
</head>

<body>
<hader>
    <div class="layui-form" id="search-form">
    </div>
</hader>
<section>
    <table class="layui-hide" id="table" lay-filter="table"></table>
</section>

</body>

<!--<script type="text/html" id="barDemo">-->
<!--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
<!--<a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>-->
<!--</script>-->

<script type="text/html" id="formTpl">
    <div id="form" class="layui-form" style="margin-top: 20px;margin-right:30px;">
        <div class="layui-form-item">
            <label class="layui-form-label">配置名称</label>
            <div class="layui-input-block">
                <input readonly="true" value="" type="text" name="configKey" lay-verify="required" id="configKey"
                       autocomplete="off" placeholder="无配置" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">配置值</label>
            <div class="layui-input-block">
                <textarea name="configValue" id="configValue" lay-verify="required" autocomplete="off" placeholder="请输入配置值"
                          class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea readonly="true" name="ds" id="ds" autocomplete="off" placeholder="无描述"
                          class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="center">
                <button class="layui-btn layui-btn-danger" lay-submit="" lay-filter="sub">保存</button>
                <button class="layui-btn layui-btn-primary" onclick="layer.closeAll();">关闭</button>
        </div>
    </div>
</script>
<script type="text/html" id="formTp2">
    <div id="form1" class="layui-form" style="margin-top: 20px;margin-right:30px;">
        <div class="layui-form-item">
            <label class="layui-form-label">配置名称</label>
            <div class="layui-input-block">
                <input value="" type="text" name="configKey" lay-verify="required"
                       autocomplete="off" placeholder="请输入配置" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">配置值</label>
            <div class="layui-input-block">
                <textarea name="configValue" lay-verify="required" autocomplete="off" placeholder="请输入配置值"
                          class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea name="ds" autocomplete="off" placeholder="请输入描述"
                          class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="center">
                <button class="layui-btn layui-btn-danger" lay-submit="" lay-filter="sub">保存</button>
                <button class="layui-btn layui-btn-primary" onclick="layer.closeAll();">关闭</button>
        </div>
    </div>
</script>
<script type="text/javascript" src="../inc/g.js"></script>
<script type="text/javascript" src="../inc/layui/layui.js"></script>
<script type="text/javascript">
    function pageload() {
        //方法级渲染
        Comm.table.render({
            elem: '#table',
            url: config.root + '/admin/config/list',
            where: {},
            cols: [
                [/*{
                    checkbox: true
                },*/
                    {type: 'radio', align: 'center', width: 80},
                    /*    {
                            field: 'syskey',
                            title: '配置名称',
                        },*/
                    {
                        field: 'ds',
                        title: '描述',
                    },
                    {
                        field: 'configValue',
                        title: '配置值',
                    },

                    // {
                    // 	field: '',
                    // 	title: '仅管理员可见',
                    // 	templet: function(d) {
                    // 		return d.admin == 1 ? '是' : '否';
                    // 	}
                    // },
                    // {
                    // 	field:'type',
                    // 	title:'类型',
                    // }
                    /*    {
                            field: '',
                            title: '操作',
                            templet: '#barDemo',
                            width: 260,
                        },*/
                ]
            ],
            id: 'table',
            ///height: 'full-' + ($(".layui-form").height() - 50),
            height: 'full-' + ($("hader").height()), //计算table底部距离
        });

        Comm.table.on('tool(table)', function (obj) {
            var syskey = obj.data.syskey;
            var sysvalue = obj.data.sysvalue;
            var ds = obj.data.ds;
            var admin = obj.data.admin;
            var type = obj.data.type;
            if (obj.event == 'edit') {

            } else if (obj.event == 'delete') {

            }
        });
    }


    function update() {
        var d = Comm.table.checkStatus('table'); //获取选中的数据
        if (d.data.length != 1) {
            Comm.msg("请选择一条数据", 5)
            return;
        }
        d = d.data[0];
        Comm.laytpl($("#formTpl").html()).render(d, function (html) {
            layer.open({
                type: 1,
                title: '编辑系统配置',
                area: ['500px', '450px'],
                maxmin: true,
                content: html,
                success: function (layero) {
                    document.getElementById('configKey').value = d.configKey;
                    document.getElementById('configValue').value = d.configValue;
                    document.getElementById('ds').value = d.ds;
                    Comm.form.on('submit(sub)', function (data) {
                        var configValue = data.field.configValue;
                        var configKey = data.field.configKey;
                        var ds = data.field.ds;

                        Comm.confirm('该数据很重要，请注意数据格式，依然修改？', function () {
                            AJAX.POST('/admin/config/update', {
                                configKey: configKey,
                                configValue: configValue,
                                ds: ds
                            }, function (d) {
                                if (d.code == 1) {
                                    Comm.layer.closeAll();
                                    Comm.msg('修改成功', 1);
                                    Comm.table.reload('table');
                                } else {
                                    Comm.msg(d.msg, 5);
                                }
                            },true,true)
                        });
                    });
                }
            });
        });
    }

    function add(d) {
        d = d == undefined ? {} : d;
        Comm.laytpl($("#formTp2").html()).render(d, function (html) {
            layer.open({
                type: 1,
                title: '新增系统配置',
                area: ['500px', '450px'],
                maxmin: true,
                content: html,
                success: function (layero) {
                    Comm.form.on('submit(sub)', function (data) {
                        AJAX.POST('/admin/sysconfig/add', data.field, function (d) {
                            if (d.code == 1) {
                                Comm.layer.closeAll();
                                Comm.msg('新增成功', 1);
                                Comm.table.reload('table');
                            } else {
                                Comm.msg(d.msg, 5);
                            }
                        });
                    });
                }
            });
        })
        ;
    }

    function del() {
        var d = Comm.table.checkStatus('table'); //获取选中的数据
        if (d.data.length < 1) {
            Comm.msg("请选择至少一条数据", 5)
            return;
        }
        var ids = [];
        for (var i = 0; i < d.data.length; i++) {
            ids.push(d.data[i].syskey)
        }
        Comm.confirm('确定删除？', function () {
            AJAX.GET('/admin/sysconfig/delete?key=' + ids.join(","), function (d) {
                if (d.code == 1) {
                    Comm.layer.closeAll()
                    Comm.msg("删除成功", 1);
                    Comm.table.reload('table');
                } else {
                    layer.closeAll();
                    Comm.msg(d.msg, {icon: 5})
                }
            });
        });
    }

    //刷新
    function reference() {
        Comm.table.reload('table');
    }
</script>

</html>
